//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see http://www.gnu.org/licenses/.
// 

#ifndef RATEBASEDADMISSIONCONTROL_H_
#define RATEBASEDADMISSIONCONTROL_H_

#include <list>
#include "AbstractAdmissionControl.h"

class Stream{
private:
	int src;
	int priority;
	double duration;
	double average;
	double lastTime;
	double initial;
	double factor;

public:
	Stream(int s, int p, double time, double len, double avg) : src(s), priority(p), duration(0.0), average(avg), lastTime(time), initial(len), factor(((double)p)/avg) {};
	~Stream() {};
	double getFactor() const {return factor;};
	double getAverage() const {return average;};
	bool isStream(int s, int p) const;
	void update(double newTime, int size);
	bool isEnd(double time, double maxTime) const;
};

class RateBasedAdmissionControl: public AbstractAdmissionControl {

	// informuje kiedy koniec strumienia
	double streamTerminate;

	// maksymalny rozmiar sumy strumieni
	int maxDataSize;

	// srednia przepustowosc
	double average;

	// lista stumieni
	std::list<Stream*> streams;


	// lista pomocnicza predkosci dla strumieni
	std::list<double> speed;

	// rozmiar lity
	int lSize;

	// ilosc aktywnych strumieni
	int activeStreams;

	virtual void initialize();
	virtual bool acceptPacket(NetPacket* packet);

};

#endif /* RATEBASEDADMISSIONCONTROL_H_ */
